﻿
//同步信息
function Sync(dataType) {
    var index = layer.load(1, { shade: [0.7, '#393D49'] }, { shadeClose: true }); //0代表加载的风格，支持0-2
    $.ajax({
        url: "../Basis/SyncData?dataType="+dataType,
        type: "post",
        success: function (data) {
            msg = "数据同步完成";
            if (data.Message != null) {
                msg = data.Message
            }
            layer.msg(msg);
            layer.close(index);
        }
    });
}

/**
系统字典下拉框数据显示
dataType:数据类型编码
controlId:控件ID
defaultValue:默认值
multiSelect:是否多选
**/
function DictionaryDropDown(dataType, controlId, defaultValue,multiSelect) {
    $.ajax({
        url: "../Basis/getDictionaryInfo",
        data: { type: dataType },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                for (var i = 0; i < datas.length; i++) {
                    $("#" + controlId).append("<option value=\"" + datas[i]["code"] + "\" >" + datas[i]["name"] + "</option>");
                }
              
                if (multiSelect != undefined && multiSelect) {
                   // moreSelect();
                } else {
                 if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                 }
                 layui.use('form', function () {
                   var form = layui.form;
                   form.render();
                 });
                }
               
            }
        }
    });
}


/**
部门信息下拉框
**/
function LoadDept(fileName) {

    $.ajax({
        url: "../System/GetDeptInfo",
        dataType: "json",
        type: "POST",
        success: function (rsl) {
            if (rsl.Result) {
                var reData = rsl.Data;
                for (var i = 0; i < reData.length; i++) {
                    $("#" + fileName).append("<option value='" + reData[i].depCode + "'>" + reData[i].depName + "(" + reData[i].depCode + ")" + "</option>");
                }
            }
            layui.use('form', function () {
                var form = layui.form;
                form.render();
            });
        }
    })
}
/**
仓库数据绑定
fileName：控件ID
**/
function WareHouseSelect(fileName, defaultValue) {

    $.ajax({
        url: "../Basis/GetDataList?dataType=wareHouse&page=1&limit=9999",
        dataType: "json",
        type: "GET",
        success: function (data) {
            var datas = data.data;
            $("#" + fileName).empty();
            for (var i = 0; i < datas.length; i++) {
                $("#" + fileName).append("<option value=\"" + datas[i]["houseCode"] + "\" >" + datas[i]["houseName"] + "(" + datas[i]["houseCode"] + ")" + "</option>");
            }
            if (defaultValue != undefined && defaultValue != "") {
                $("#" + fileName + " option[value='" + defaultValue + "'] ").attr("selected", true);
            }
            layui.use('form', function () {
                var form = layui.form;
                form.render();
            });
        }
    });
}


function wareInfo(fileName) {
    $.ajax({
        url: "../Basis/GetWareHouse",
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                for (var i = 0; i < datas.length; i++) {
                    $("#" + fileName).append("<option value=\"" + datas[i]["houseCode"] + "\" >" + datas[i]["houseName"] + "</option>");
                }

            }
            layui.use('form', function () {
                var form = layui.form;
                form.render();
            });
        }
    });
}

/**
仓库数据绑定
fileName：控件ID
**/
function WarePositionSelect(fileName,wareHouse) {

    $.ajax({
        url: "../Basis/GetWareHousePosition",
        data: { wareCode: wareHouse },
        dataType: "json",
        type: "POST",
        success: function (data) {
            var datas = data.Data;
            $("#" + fileName).empty();
            if (datas != null) {
                for (var i = 0; i < datas.length; i++) {
                    $("#" + fileName).append("<option value=\"" + datas[i]["code"] + "\" >" + datas[i]["name"] + "</option>");
                }
            } else {
                $("#" + fileName).append("<option value=\" \" > </option>");
            }
            layui.use('form', function () {
                var form = layui.form;
                form.render();
            });
        }
    });
}
/**
 通用数据获取方法(下拉框)
type:通用数据类型
controlId:控件ID
defaultValue:默认值
 **/
function CommonData(type, controlId, defaultValue) {
    $.ajax({
        url: "../Basis/GetCommonData",
        data: { type: type },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                $("select[name='"+controlId+"'] option:gt(0)").remove();   //先清空除第一个以外全部的option  ，再重新添加
                for (var i = 0; i < datas.length; i++) {
                    if (datas[i]["cCode"] != "") {
                        $("#" + controlId).append("<option value=\"" + datas[i]["cCode"] + "\" >" + datas[i]["cName"] + "(" + datas[i]["cCode"] + ")" + "</option>");
                    }
                   
                }
                if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
}
/**
工序机台
**/
function GongXuMachine(gxCode, controlId, defaultValue) {
    $.ajax({
        url: "../ProductSet/GetGxMachine",
        data: { gxCode: gxCode },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                var sContents = "<option value=''>选择机台</option>"
                for (var i = 0; i < datas.length; i++) {
                    sContents += "<option value=\"" + datas[i]["cCode"] + "\" >" + datas[i]["cName"] + "(" + datas[i]["cCode"] +")"+ "</option>";
                }
                $("#" + controlId).empty();
                $("#" + controlId).append(sContents);
                if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
}

/**
生产机台（织造）
**/
function GetZBMachine(mType,controlId, defaultValue) {
    $.ajax({
        url: "../ProductSet/GetZBMachine",
        data: { mType: mType },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                //$("#" + controlId).empty();
                var sContents = "<option value=''>选择机台</option>"
                for (var i = 0; i < datas.length; i++) {
                    sContents += "<option value=\"" + datas[i]["mCode"] + "\" >" + datas[i]["mName"] + "(" + datas[i]["mCode"] + ")" + "</option>";
                    //$("#" + controlId).append("<option value=\"" + datas[i]["mCode"] + "\" >" + datas[i]["mName"] + "(" + datas[i]["mCode"] + ")" + "</option>");
                }
                $("#" + controlId).empty();
                $("#" + controlId).append(sContents);
                if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
}

/**
子工序下拉
**/
function GongXuChildren(gxCode, controlId, defaultValue) {
    $.ajax({
        url: "../ProductSet/GongXuChildren",
        data: { gxCode: gxCode },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                var sContents = ""
                for (var i = 0; i < datas.length; i++) {
                    sContents += "<option value=\"" + datas[i]["cCode"] + "\" >" + datas[i]["cName"] + "(" + datas[i]["cCode"] + ")" + "</option>";
                }
                $("#" + controlId).empty();
                $("#" + controlId).append(sContents);
                if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
}

//选择存货下拉列表
function getProName(name, controlId, defaultValue) {
    $.ajax({
        url: "../ProductSet/getproName",
        data: { name: name },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                for (var i = 0; i < datas.length; i++) {
                    if (datas[i]["cCode"] != "") {
                        $("#" + controlId).append("<option value=\"" + datas[i]["proCode"] + "\" >" + datas[i]["proName"] + "(" + datas[i]["proCode"] + ")" + "</option>");
                    }
                }
                if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
}

//选择员工下拉列表
function getUsers(userCode, controlId, defaultValue) {
    $.ajax({
        url: "../ProductSet/getUsers",
        data: { userCode: userCode },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                for (var i = 0; i < datas.length; i++) {
                    if (datas[i]["cCode"] != "") {
                        $("#" + controlId).append("<option value=\"" + datas[i]["userCode"] + "\" >" + datas[i]["userName"] + "(" + datas[i]["userCode"] + ")" + "</option>");
                    }
                }
                if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
}

